home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 1.iso / toolbox / src / exampleCode / opengl / GLUT / progs / demos / walker / models.c < prev    next >
C/C++ Source or Header  |  1996-11-11  |  18KB  |  692 lines

  1. #include <GL/glut.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <math.h>
  5.  
  6. #include "walker.h"
  7.  
  8.  
  9.   /* for cube models */
  10. #define UPPER_LEG_SIZE_C 0.45
  11. #define LOWER_LEG_SIZE_C 0.45
  12. #define UPPER_ARM_SIZE_C 0.4
  13. #define LOWER_ARM_SIZE_C 0.4
  14. #define FOOT_SIZE_C 0.2
  15. #define HEAD_SIZE_C 0.25
  16. #define TORSO_HEIGHT_C 0.8
  17. #define TORSO_WIDTH_C 0.5
  18. #define LEG_GIRTH_C 0.1
  19. #define ARM_GIRTH_C 0.05
  20.  
  21.   /* for cylinder models */
  22. #define UPPER_LEG_SIZE 0.5
  23. #define LOWER_LEG_SIZE 0.5
  24. #define LEG_GIRTH 0.08
  25. #define UPPER_LEG_GIRTH 0.1
  26. #define UPPER_LEG_TAPER 0.8
  27. #define LOWER_LEG_TAPER 0.8
  28. #define LOWER_LEG_GIRTH 0.07
  29.  
  30. #define UPPER_ARM_SIZE 0.45
  31. #define LOWER_ARM_SIZE 0.45
  32. #define ARM_GIRTH 0.05
  33. #define UPPER_ARM_GIRTH 0.05
  34. #define LOWER_ARM_GIRTH 0.04
  35. #define UPPER_ARM_TAPER 0.8
  36. #define LOWER_ARM_TAPER 0.8
  37.  
  38. #define HIP_JOINT_SIZE 0.1
  39. #define KNEE_JOINT_SIZE 0.09
  40. #define SHOULDER_JOINT_SIZE 0.05
  41. #define ELBOW_JOINT_SIZE 0.045
  42.  
  43. #define HEAD_SIZE 0.2
  44. #define FOOT_SIZE 0.15
  45.  
  46. #define TORSO_HEIGHT 0.8
  47. #define TORSO_WIDTH 0.35
  48. #define TORSO_TAPER 0.7
  49.  
  50. #define STACKS 10
  51. #define SLICES 10
  52.  
  53. #define NUM_BODY_PARTS 7
  54.  
  55.  
  56. #define LEFT 0
  57. #define RIGHT 1
  58. #define SOLID 1
  59. #define WIRE 0
  60.  
  61.  
  62.  
  63. void DrawTheGuy_WC(void);
  64. void DrawTheGuy_SC(void);
  65. void draw_head_C(int solid);
  66. void draw_torso_C(int solid);
  67. void draw_leg_C(int which, int solid);
  68. void draw_arm_C(int which, int solid);
  69.  
  70. void StoreTheGuy_SL(void);
  71. void DrawTheGuy_SL(void);
  72. void draw_head_SL(void);
  73. void draw_torso_SL(void);
  74. void draw_leg_SL(int which);
  75. void draw_arm_SL(int which);
  76. void store_head_SL(void);
  77. void store_torso_SL(void);
  78. void store_uleg_SL(void);
  79. void store_lleg_SL(void);
  80. void store_foot_SL(void);
  81. void store_uarm_SL(void);
  82. void store_larm_SL(void);
  83.  
  84. void StoreTheGuy_SL2(void);
  85. void DrawTheGuy_SL2(void);
  86. void draw_head_SL2(void);
  87. void draw_torso_SL2(void);
  88. void draw_leg_SL2(int which);
  89. void draw_arm_SL2(int which);
  90. void store_head_SL2(void);
  91. void store_torso_SL2(void);
  92. void store_uleg_SL2(void);
  93. void store_lleg_SL2(void);
  94. void store_foot_SL2(void);
  95. void store_uarm_SL2(void);
  96. void store_larm_SL2(void);
  97.  
  98. /**************************************************************/
  99. void DrawTheGuy_WC(void)
  100. {
  101.   draw_head_C(WIRE);
  102.   draw_torso_C(WIRE);
  103.   draw_leg_C(LEFT,  WIRE);
  104.   draw_leg_C(RIGHT, WIRE);
  105.   draw_arm_C(LEFT,  WIRE);
  106.   draw_arm_C(RIGHT, WIRE);
  107. }
  108.  
  109. /**************************************************************/
  110. void DrawTheGuy_SC(void)
  111. {
  112.   GLfloat head_diffuse[] = { 0.7, 0.7, 0.0, 1.0 };
  113.   GLfloat torso_diffuse[] = { 0.0, 0.7, 0.7, 1.0 };
  114.   GLfloat leg_diffuse[] = { 0.7, 0.0, 0.7, 1.0 };
  115.   GLfloat arm_diffuse[] = { 0.7, 0.4, 0.4, 1.0 };
  116.  
  117.   glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, head_diffuse);
  118.   draw_head_C(SOLID);
  119.  
  120.   glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, torso_diffuse);
  121.   draw_torso_C(SOLID);
  122.  
  123.   glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, leg_diffuse);
  124.   draw_leg_C(LEFT,  SOLID);
  125.   draw_leg_C(RIGHT, SOLID);
  126.  
  127.   glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, arm_diffuse);
  128.   draw_arm_C(LEFT,  SOLID);
  129.   draw_arm_C(RIGHT, SOLID);
  130. }
  131.  
  132.  
  133.  
  134. /**********************************************************/
  135. void draw_head_C(int solid)
  136. {
  137.   glPushMatrix();
  138.   glColor3f(1.0, 1.0, 0.0);
  139.   glTranslatef(0.0, TORSO_HEIGHT_C+(HEAD_SIZE_C/1.5), 0.0);
  140.   glScalef(HEAD_SIZE_C, HEAD_SIZE_C, LEG_GIRTH_C);
  141.   if (solid)
  142.     glutSolidCube(1.0);
  143.   else
  144.     glutWireCube(1.0);
  145.   glPopMatrix();
  146. }
  147.  
  148. /**********************************************************/
  149. void draw_torso_C(int solid)
  150. {
  151.   glPushMatrix();
  152.   glColor3f(0.0, 1.0, 1.0);
  153.   glTranslatef(0.0, TORSO_HEIGHT_C/2.0, 0.0);
  154.   glScalef(TORSO_WIDTH_C, TORSO_HEIGHT_C, LEG_GIRTH_C);
  155.   if (solid)
  156.     glutSolidCube(1.0);
  157.   else
  158.     glutWireCube(1.0);
  159.   glPopMatrix();
  160. }
  161.  
  162. /**********************************************************/
  163. void draw_leg_C(int which, int solid)
  164. {
  165.   glPushMatrix();
  166.   if (which == 0)
  167.     glTranslatef(TORSO_WIDTH_C/4.0, 0.0, 0.0);
  168.   else glTranslatef(-TORSO_WIDTH_C/4.0, 0.0, 0.0);
  169.   /* Upper leg: rotates about the x axis only */
  170.   glColor3f(1.0, 0.0, 0.0);
  171.   glRotatef(Walk_cycle[which][0][Step],1.0, 0.0, 0.0);
  172.   glPushMatrix();
  173.   glTranslatef(0.0, -UPPER_LEG_SIZE_C/2.0, 0.0);
  174.   glScalef(LEG_GIRTH_C, UPPER_LEG_SIZE_C, LEG_GIRTH_C);
  175.   if (solid)
  176.     glutSolidCube(1.0);
  177.   else
  178.     glutWireCube(1.0);
  179.   glPopMatrix();
  180.  
  181.   /* Lower leg: rotates about the x axis only */
  182.   glColor3f(0.0, 1.0, 0.0);
  183.   glTranslatef(0.0, -(UPPER_LEG_SIZE_C+LOWER_LEG_SIZE_C)/2.0, 0.0);
  184.   glRotatef(Walk_cycle[which][1][Step], 1.0, 0.0, 0.0);
  185.   glPushMatrix();
  186.   glTranslatef(0.0, -LOWER_LEG_SIZE_C/2.0, 0.0);
  187.   glScalef(LEG_GIRTH_C, LOWER_LEG_SIZE_C, LEG_GIRTH_C);
  188.   if (solid)
  189.     glutSolidCube(1.0);
  190.   else
  191.     glutWireCube(1.0);
  192.   glPopMatrix();
  193.  
  194.   /* Foot: rotates about the x axis only */
  195.   glColor3f(0.0, 0.0, 1.0);
  196.  
  197.   glTranslatef(0.0, -(UPPER_LEG_SIZE_C+LOWER_LEG_SIZE_C+LEG_GIRTH_C)/2.0, 0.0);
  198.   glRotatef(Walk_cycle[which][2][Step], 1.0, 0.0, 0.0);
  199.   glPushMatrix();
  200.   glTranslatef(0.0, -LEG_GIRTH_C/2.0, -FOOT_SIZE_C/4.0);
  201.   glScalef(LEG_GIRTH_C, LEG_GIRTH_C, FOOT_SIZE_C);
  202.   if (solid)
  203.     glutSolidCube(1.0);
  204.   else
  205.     glutWireCube(1.0);
  206.   glPopMatrix();
  207.  
  208.   glPopMatrix();
  209. }
  210.  
  211. /*********************************************************************/
  212. void draw_arm_C(int which, int solid)
  213. {
  214.   int arm_which;
  215.  
  216.   if (which == 1)
  217.     arm_which = 1;
  218.   else arm_which = 0;
  219.  
  220.   glPushMatrix();
  221.   glTranslatef(0.0, TORSO_HEIGHT_C, 0.0);
  222.   if (which == 0)
  223.     glTranslatef(TORSO_WIDTH_C/1.5, 0.0, 0.0);
  224.   else glTranslatef(-TORSO_WIDTH_C/1.5, 0.0, 0.0);
  225.   /* Upper leg: rotates about the x axis only */
  226.   glColor3f(1.0, 0.0, 0.0);
  227.   glRotatef(Walk_cycle[arm_which][3][Step],1.0, 0.0, 0.0);
  228.   glPushMatrix();
  229.   glTranslatef(0.0, -UPPER_ARM_SIZE_C/2.0, 0.0);
  230.   glScalef(ARM_GIRTH_C, UPPER_ARM_SIZE_C, ARM_GIRTH_C);
  231.   if (solid)
  232.     glutSolidCube(1.0);
  233.   else
  234.     glutWireCube(1.0);
  235.   glPopMatrix();
  236.  
  237.   /* Lower leg: rotates about the x axis only */
  238.   glColor3f(0.0, 1.0, 0.0);
  239.   glTranslatef(0.0, -(UPPER_ARM_SIZE_C+LOWER_ARM_SIZE_C)/2.0, 0.0);
  240.   glRotatef(Walk_cycle[arm_which][4][Step], 1.0, 0.0, 0.0);
  241.   glPushMatrix();
  242.   glTranslatef(0.0, -LOWER_ARM_SIZE_C/2.0, 0.0);
  243.   glScalef(ARM_GIRTH_C, LOWER_ARM_SIZE_C, ARM_GIRTH_C);
  244.   if (solid)
  245.     glutSolidCube(1.0);
  246.   else
  247.     glutWireCube(1.0);
  248.   glPopMatrix();
  249.  
  250.   glPopMatrix();
  251. }
  252.  
  253.  
  254.  
  255.  
  256. GLUquadricObj *quadObj;
  257. GLuint body_lists;
  258.  
  259. /**************************************************************/
  260. void StoreTheGuy_SL(void)
  261. {
  262.   quadObj = gluNewQuadric();
  263.  
  264.   body_lists = glGenLists(NUM_BODY_PARTS);
  265.  
  266.   glNewList(body_lists, GL_COMPILE);
  267.   store_head_SL();
  268.   glEndList();
  269.  
  270.   glNewList(body_lists+1, GL_COMPILE);
  271.   store_torso_SL();
  272.   glEndList();
  273.  
  274.   glNewList(body_lists+2, GL_COMPILE);
  275.   store_uleg_SL();
  276.   glEndList();
  277.  
  278.   glNewList(body_lists+3, GL_COMPILE);
  279.   store_lleg_SL();
  280.   glEndList();
  281.  
  282.   glNewList(body_lists+4, GL_COMPILE);
  283.   store_foot_SL();
  284.   glEndList();
  285.  
  286.   glNewList(body_lists+5, GL_COMPILE);
  287.   store_uarm_SL();
  288.   glEndList();
  289.  
  290.   glNewList(body_lists+6, GL_COMPILE);
  291.   store_larm_SL();
  292.   glEndList();
  293.  
  294. }
  295.  
  296. /**********************************************************/
  297. void store_head_SL(void)
  298.   glPushMatrix();
  299.   glTranslatef(0.0, TORSO_HEIGHT+HEAD_SIZE, 0.0);
  300.   glScalef(HEAD_SIZE, HEAD_SIZE, LEG_GIRTH);
  301.   glutSolidSphere(1.0, SLICES, STACKS);
  302.   glPopMatrix();
  303. }
  304.  
  305. /**********************************************************/
  306. void store_torso_SL(void)
  307. {
  308.   glPushMatrix();
  309.   glScalef(TORSO_WIDTH, TORSO_HEIGHT, LEG_GIRTH);
  310.   glRotatef(-90.0, 1.0, 0.0, 0.0);
  311.   gluCylinder(quadObj, TORSO_TAPER, 1.0, 1.0, SLICES, STACKS);
  312.   glPopMatrix();
  313. }
  314.  
  315. /**************************************************************/
  316. void store_uleg_SL(void)
  317. {
  318.   glPushMatrix();
  319.   glScalef(LEG_GIRTH, UPPER_LEG_SIZE, LEG_GIRTH);
  320.   glRotatef(90.0, 1.0, 0.0, 0.0);
  321.   gluCylinder(quadObj, 1.0, 1.0, 1.0, SLICES, STACKS);
  322.   glPopMatrix();
  323. }
  324.   
  325. /**************************************************************/
  326. void store_lleg_SL(void)
  327. {
  328.   glPushMatrix();
  329.   glScalef(LEG_GIRTH, LOWER_LEG_SIZE, LEG_GIRTH);
  330.   glRotatef(90.0, 1.0, 0.0, 0.0);
  331.   gluCylinder(quadObj, 1.0, 1.0, 1.0, SLICES, STACKS);
  332.   glPopMatrix();
  333. }
  334.   
  335. /**************************************************************/
  336. void store_foot_SL(void)
  337. {
  338.   glPushMatrix();
  339.   glTranslatef(0.0, 0.0, -FOOT_SIZE/2.0);
  340.   glScalef(LEG_GIRTH, LEG_GIRTH, FOOT_SIZE);
  341.   glRotatef(90.0, 1.0, 0.0, 0.0);
  342.   gluCylinder(quadObj, 1.0, 1.0, 1.0, SLICES, STACKS);
  343.   glPopMatrix();
  344. }
  345.   
  346. /**************************************************************/
  347. void store_uarm_SL(void)
  348. {
  349.   glPushMatrix();
  350.   glScalef(ARM_GIRTH, UPPER_ARM_SIZE, ARM_GIRTH);
  351.   glRotatef(90.0, 1.0, 0.0, 0.0);
  352.   gluCylinder(quadObj, 1.0, 1.0, 1.0, SLICES, STACKS);
  353.   glPopMatrix();
  354. }
  355.   
  356. /**************************************************************/
  357. void store_larm_SL(void)
  358. {
  359.   glPushMatrix();
  360.   glScalef(ARM_GIRTH, LOWER_ARM_SIZE, ARM_GIRTH);
  361.   glRotatef(90.0, 1.0, 0.0, 0.0);
  362.   gluCylinder(quadObj, 1.0, 1.0, 1.0, SLICES, STACKS);
  363.   glPopMatrix();
  364. }
  365.   
  366. /**************************************************************/
  367. void DrawTheGuy_SL(void)
  368. {
  369.   GLfloat head_diffuse[] =  { 0.7, 0.7, 0.0, 1.0 };
  370.   GLfloat torso_diffuse[] = { 0.0, 0.7, 0.7, 1.0 };
  371.   GLfloat leg_diffuse[] =   { 0.7, 0.0, 0.7, 1.0 };
  372.   GLfloat arm_diffuse[] =   { 0.7, 0.4, 0.4, 1.0 };
  373.  
  374.   glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, head_diffuse);
  375.   draw_head_SL();
  376.  
  377.   glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, torso_diffuse);
  378.   draw_torso_SL();
  379.  
  380.   glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, leg_diffuse);
  381.   draw_leg_SL(0);
  382.   draw_leg_SL(1);
  383.  
  384.   glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, arm_diffuse);
  385.   draw_arm_SL(0);
  386.   draw_arm_SL(1);
  387.  
  388. }
  389.  
  390. /**********************************************************/
  391. void draw_head_SL(void)
  392. {
  393.   glPushMatrix();
  394.   glCallList(body_lists);
  395.   glPopMatrix();
  396. }
  397.  
  398. /**********************************************************/
  399. void draw_torso_SL(void)
  400. {
  401.   glPushMatrix();
  402.   glCallList(body_lists+1);
  403.   glPopMatrix();
  404. }
  405.  
  406. /**********************************************************/
  407. void draw_leg_SL(int which)
  408. {
  409.   glPushMatrix();
  410.   if (which == 0)
  411.     glTranslatef(TORSO_TAPER*TORSO_WIDTH/2.0, 0.0, 0.0);
  412.   else glTranslatef(-TORSO_TAPER*TORSO_WIDTH/2.0, 0.0, 0.0);
  413.   /* Upper leg: rotates about the x axis only */
  414.   glRotatef(Walk_cycle[which][0][Step],1.0, 0.0, 0.0);
  415.   glPushMatrix();
  416.   glCallList(body_lists+2);
  417.   glPopMatrix();
  418.  
  419.   /* Lower leg: rotates about the x axis only */
  420.   glTranslatef(0.0, -(UPPER_LEG_SIZE+LOWER_LEG_SIZE)/2.0, 0.0);
  421.   glRotatef(Walk_cycle[which][1][Step], 1.0, 0.0, 0.0);
  422.   glPushMatrix();
  423.   glCallList(body_lists+3);
  424.   glPopMatrix();
  425.  
  426.   /* Foot: rotates about the x axis only */
  427.   glTranslatef(0.0, -(UPPER_LEG_SIZE+LOWER_LEG_SIZE+LEG_GIRTH)/2.0, 0.0);
  428.   glRotatef(Walk_cycle[which][2][Step], 1.0, 0.0, 0.0);
  429.   glPushMatrix();
  430.   glCallList(body_lists+4);
  431.   glPopMatrix();
  432.  
  433.   glPopMatrix();
  434. }
  435.  
  436. /*********************************************************************/
  437. void draw_arm_SL(int which)
  438. {
  439.   int arm_which;
  440.  
  441.   if (which == 1)
  442.     arm_which = 1;
  443.   else arm_which = 0;
  444.  
  445.   glPushMatrix();
  446.   glTranslatef(0.0, TORSO_HEIGHT, 0.0);
  447.   if (which == 0)
  448.     glTranslatef(TORSO_WIDTH, 0.0, 0.0);
  449.   else glTranslatef(-TORSO_WIDTH, 0.0, 0.0);
  450.   /* Upper leg: rotates about the x axis only */
  451.   glRotatef(Walk_cycle[arm_which][3][Step],1.0, 0.0, 0.0);
  452.   glPushMatrix();
  453.   glCallList(body_lists+5);
  454.   glPopMatrix();
  455.  
  456.   /* Lower leg: rotates about the x axis only */
  457.   glTranslatef(0.0, -(UPPER_ARM_SIZE+LOWER_ARM_SIZE)/2.0, 0.0);
  458.   glRotatef(Walk_cycle[arm_which][4][Step], 1.0, 0.0, 0.0);
  459.   glPushMatrix();
  460.   glCallList(body_lists+6);
  461.   glPopMatrix();
  462.  
  463.   glPopMatrix();
  464. }
  465.  
  466.  
  467.  
  468. GLUquadricObj *quadObj2;
  469. GLuint body_lists2;
  470.  
  471. /**************************************************************/
  472. void StoreTheGuy_SL2(void)
  473. {
  474.   quadObj2 = gluNewQuadric();
  475.  
  476.   body_lists2 = glGenLists(NUM_BODY_PARTS);
  477.  
  478.   glNewList(body_lists2, GL_COMPILE);
  479.   store_head_SL2();
  480.   glEndList();
  481.  
  482.   glNewList(body_lists2+1, GL_COMPILE);
  483.   store_torso_SL2();
  484.   glEndList();
  485.  
  486.   glNewList(body_lists2+2, GL_COMPILE);
  487.   store_uleg_SL2();
  488.   glEndList();
  489.  
  490.   glNewList(body_lists2+3, GL_COMPILE);
  491.   store_lleg_SL2();
  492.   glEndList();
  493.  
  494.   glNewList(body_lists2+4, GL_COMPILE);
  495.   store_foot_SL2();
  496.   glEndList();
  497.  
  498.   glNewList(body_lists2+5, GL_COMPILE);
  499.   store_uarm_SL2();
  500.   glEndList();
  501.  
  502.   glNewList(body_lists2+6, GL_COMPILE);
  503.   store_larm_SL2();
  504.   glEndList();
  505.  
  506. }
  507.  
  508. /**********************************************************/
  509. void store_head_SL2(void)
  510.   glPushMatrix();
  511.   glTranslatef(0.0, TORSO_HEIGHT+HEAD_SIZE, 0.0);
  512.   glScalef(HEAD_SIZE, HEAD_SIZE, UPPER_LEG_GIRTH);
  513.   glutSolidSphere(1.0, SLICES, STACKS);
  514.   glPopMatrix();
  515. }
  516.  
  517. /**********************************************************/
  518. void store_torso_SL2(void)
  519. {
  520.   glPushMatrix();
  521.   glScalef(TORSO_WIDTH, TORSO_HEIGHT, UPPER_LEG_GIRTH);
  522.   glRotatef(-90.0, 1.0, 0.0, 0.0);
  523.   gluCylinder(quadObj2, TORSO_TAPER, 1.0, 1.0, SLICES, STACKS);
  524.   glPopMatrix();
  525. }
  526.  
  527. /**************************************************************/
  528. void store_uleg_SL2(void)
  529. {
  530.   glPushMatrix();
  531.   glTranslatef(0.0, -(HIP_JOINT_SIZE+UPPER_LEG_SIZE), 0.0);
  532.   glutSolidSphere(KNEE_JOINT_SIZE, SLICES, STACKS);
  533.   glPopMatrix();
  534.   glTranslatef(0.0, -HIP_JOINT_SIZE, 0.0);
  535.   glutSolidSphere(HIP_JOINT_SIZE, SLICES, STACKS);
  536.   glPushMatrix();
  537.   glScalef(UPPER_LEG_GIRTH, UPPER_LEG_SIZE, UPPER_LEG_GIRTH);
  538.   glRotatef(90.0, 1.0, 0.0, 0.0);
  539.   gluCylinder(quadObj2, 1.0, UPPER_LEG_TAPER, 1.0, SLICES, STACKS);
  540.   glPopMatrix();
  541. }
  542.   
  543. /**************************************************************/
  544. void store_lleg_SL2(void)
  545. {
  546.   glPushMatrix();
  547.   glScalef(LOWER_LEG_GIRTH, LOWER_LEG_SIZE, LOWER_LEG_GIRTH);
  548.   glRotatef(90.0, 1.0, 0.0, 0.0);
  549.   gluCylinder(quadObj2, 1.0, LOWER_LEG_TAPER, 1.0, SLICES, STACKS);
  550.   glPopMatrix();
  551. }
  552.   
  553. /**************************************************************/
  554. void store_foot_SL2(void)
  555. {
  556.   glPushMatrix();
  557.   glTranslatef(0.0, 0.0, -FOOT_SIZE/2.0);
  558.   glScalef(LOWER_LEG_GIRTH, LOWER_LEG_GIRTH, FOOT_SIZE);
  559.   glRotatef(90.0, 1.0, 0.0, 0.0);
  560.   gluCylinder(quadObj2, 1.0, 1.0, 1.0, SLICES, STACKS);
  561.   glPopMatrix();
  562. }
  563.   
  564. /**************************************************************/
  565. void store_uarm_SL2(void)
  566. {
  567.   glPushMatrix();
  568.   glTranslatef(0.0, -(SHOULDER_JOINT_SIZE+UPPER_ARM_SIZE), 0.0);
  569.   glutSolidSphere(ELBOW_JOINT_SIZE, SLICES, STACKS);
  570.   glPopMatrix();
  571.   glTranslatef(0.0, -SHOULDER_JOINT_SIZE, 0.0);
  572.   glutSolidSphere(SHOULDER_JOINT_SIZE, SLICES, STACKS);
  573.   glPushMatrix();
  574.   glScalef(UPPER_ARM_GIRTH, UPPER_ARM_SIZE, UPPER_ARM_GIRTH);
  575.   glRotatef(90.0, 1.0, 0.0, 0.0);
  576.   gluCylinder(quadObj2, 1.0, UPPER_ARM_TAPER, 1.0, SLICES, STACKS);
  577.   glPopMatrix();
  578. }
  579.   
  580. /**************************************************************/
  581. void store_larm_SL2(void)
  582. {
  583.   glPushMatrix();
  584.   glScalef(LOWER_ARM_GIRTH, LOWER_ARM_SIZE, LOWER_ARM_GIRTH);
  585.   glRotatef(90.0, 1.0, 0.0, 0.0);
  586.   gluCylinder(quadObj2, 1.0, LOWER_ARM_TAPER, 1.0, SLICES, STACKS);
  587.   glPopMatrix();
  588. }
  589.  
  590. /**************************************************************/
  591. void DrawTheGuy_SL2(void)
  592. {
  593.   GLfloat head_diffuse[] = { 0.7, 0.7, 0.0, 1.0 };
  594.   GLfloat torso_diffuse[] = { 0.0, 0.7, 0.7, 1.0 };
  595.   GLfloat leg_diffuse[] = { 0.7, 0.0, 0.7, 1.0 };
  596.   GLfloat arm_diffuse[] = { 0.7, 0.4, 0.4, 1.0 };
  597.  
  598.   glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, head_diffuse);
  599.   draw_head_SL2();
  600.  
  601.   glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, torso_diffuse);
  602.   draw_torso_SL2();
  603.  
  604.   glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, leg_diffuse);
  605.   draw_leg_SL2(0);
  606.   draw_leg_SL2(1);
  607.  
  608.   glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, arm_diffuse);
  609.   draw_arm_SL2(0);
  610.   draw_arm_SL2(1);
  611.  
  612. }
  613.  
  614. /**********************************************************/
  615. void draw_head_SL2(void)
  616. {
  617.   glPushMatrix();
  618.   glCallList(body_lists2);
  619.   glPopMatrix();
  620. }
  621.  
  622. /**********************************************************/
  623. void draw_torso_SL2(void)
  624. {
  625.   glPushMatrix();
  626.   glCallList(body_lists2+1);
  627.   glPopMatrix();
  628. }
  629.  
  630. /**********************************************************/
  631. void draw_leg_SL2(int which)
  632. {
  633.   glPushMatrix();
  634.   if (which == 0)
  635.     glTranslatef(TORSO_TAPER*TORSO_WIDTH/2.0, 0.0, 0.0);
  636.   else glTranslatef(-TORSO_TAPER*TORSO_WIDTH/2.0, 0.0, 0.0);
  637.   /* UPPER leg: rotates about the x axis only */
  638.   glRotatef(Walk_cycle[which][0][Step],1.0, 0.0, 0.0);
  639.   glPushMatrix();
  640.   glCallList(body_lists2+2);
  641.   glPopMatrix();
  642.  
  643.   /* LOWER leg: rotates about the x axis only */
  644.   glTranslatef(0.0, -(UPPER_LEG_SIZE+KNEE_JOINT_SIZE), 0.0);
  645.   glRotatef(Walk_cycle[which][1][Step], 1.0, 0.0, 0.0);
  646.   glPushMatrix();
  647.   glCallList(body_lists2+3);
  648.   glPopMatrix();
  649.  
  650.   /* Foot: rotates about the x axis only */
  651.   glTranslatef(0.0, -(UPPER_LEG_SIZE+LOWER_LEG_SIZE+LOWER_LEG_GIRTH)/2.0, 0.0);
  652.   glRotatef(Walk_cycle[which][2][Step], 1.0, 0.0, 0.0);
  653.   glPushMatrix();
  654.   glCallList(body_lists2+4);
  655.   glPopMatrix();
  656.  
  657.   glPopMatrix();
  658. }
  659.  
  660. /*********************************************************************/
  661. void draw_arm_SL2(int which)
  662. {
  663.   int arm_which;
  664.  
  665.   if (which == 1)
  666.     arm_which = 1;
  667.   else arm_which = 0;
  668.  
  669.   glPushMatrix();
  670.   glTranslatef(0.0, TORSO_HEIGHT, 0.0);
  671.   if (which == 0)
  672.     glTranslatef(TORSO_WIDTH, 0.0, 0.0);
  673.   else glTranslatef(-TORSO_WIDTH, 0.0, 0.0);
  674.   /* UPPER leg: rotates about the x axis only */
  675.   glRotatef(Walk_cycle[arm_which][3][Step],1.0, 0.0, 0.0);
  676.   glPushMatrix();
  677.   glCallList(body_lists2+5);
  678.   glPopMatrix();
  679.  
  680.   /* LOWER leg: rotates about the x axis only */
  681.   glTranslatef(0.0, -(UPPER_ARM_SIZE+ELBOW_JOINT_SIZE), 0.0);
  682.   glRotatef(Walk_cycle[arm_which][4][Step], 1.0, 0.0, 0.0);
  683.   glPushMatrix();
  684.   glCallList(body_lists2+6);
  685.   glPopMatrix();
  686.  
  687.   glPopMatrix();
  688. }
  689.  
  690.